package com.ml.service.impl;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ml.enums.EnumPayStatus;
import com.ml.message.OrderDTO;
import com.ml.message.OrderSuccessVO;
import com.ml.mq.SendService;
import com.ml.service.OrderFactory;
import com.ml.service.StateHandler;
import com.ml.util.DataUtil;

@Component
public class PaidState implements StateHandler, InitializingBean {

	@Autowired
	private SendService sendService;

	@Override
	public OrderSuccessVO handler(OrderSuccessVO order) {
		// 发送到撮合
		order.setState(1);
		// 封装消息
		OrderDTO orderDTO = DataUtil.toOrderMessage(order);
		sendService.sendNewOrder(orderDTO.toString());
		return order;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		OrderFactory.register(EnumPayStatus.PAID, this);
	}

}
